package com.aj.service.impl;

import com.aj.entity.User;
import com.aj.mapper.UserMapper;
import com.aj.service.UserService;
import com.aj.util.Result;
import com.aj.util.TokenUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aj
 * @since 2020-08-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

	@Autowired
	UserMapper um;
	@Override
	public Result login(User u) {
		// TODO Auto-generated method stub
		try {
			User uu=um.selectByName(u.getName());
//			User uu=um.selectById(u.getName());
			if(uu.getPwd().equals(u.getPwd())) {
				return new Result(true, "成功辽", 200, TokenUtil.sign(u));
			}
			else {
				return new Result(false, "密码错误", 500, null);
			}
		}
		catch(NullPointerException e) {
			return new Result(false, "用户名错误", 501, null);
		}
		catch(Exception e) {
			e.printStackTrace();
			return new Result(false, "参数可能出错", 500, null);
		}
	}

}
